home *** CD-ROM | disk | FTP | other *** search
- /****************************** the test app *******************************/
-
- #include "Types.h"
- #include "GXTypes.h"
- #include "GXMath.h"
- #include "GXGraphics.h"
- #include "GXLayout.h"
- #include "GXExceptions.h"
-
- #include "AccurateShapes.h"
- #include "Stdio.h"
-
- #define fix2float(x) ((double)x / 65536.0)
-
-
- gxShape MakeThePath(void);
- gxShape MakeThePath(void)
- {
- static gxCurve curveGeometry = {ff(50), ff(325), ff(175), ff(150), ff(300), ff(325) };
- static gxCurve curveGeometry2 = {ff(300), ff(325), ff(425), ff(500), ff(550), ff(325) };
- gxShape nicePath;
- gxShape curve2;
-
- nicePath = GXNewCurve(&curveGeometry);
- GXSetShapeType(nicePath, gxPathType);
- curve2= GXNewCurve(&curveGeometry2);
- GXSetShapeParts(nicePath, 0, 0, curve2, gxBreakNeitherEdit);
- GXDisposeShape(curve2);
-
- GXSetShapeFill(nicePath, gxFrameFill);
-
- GXMoveShape(nicePath, ff(0), ff(-120));
-
- GXSetShapeType(nicePath, gxPolygonType);
-
- return(nicePath);
- }
-
-
-
-
-
- typedef struct {
-
- gxPoint currentPoint; // current pen
- gxPoint firstPoint; // first point in countour.
-
- } TestWalkRec;
-
-
-
- Boolean TestMoveto(gxPoint *p, TestWalkRec* pWalk);
- Boolean TestMoveto(gxPoint *p, TestWalkRec* pWalk)
- {
- pWalk->currentPoint.x = p->x;
- pWalk->currentPoint.y = p->y;
-
- pWalk->firstPoint.x = p->x;
- pWalk->firstPoint.y = p->y;
-
-
- return(false);
- }
-
-
-
- Boolean TestLineto(gxPoint *p, TestWalkRec* pWalk);
- Boolean TestLineto(gxPoint *p, TestWalkRec* pWalk)
- {
- gxLine aLine;
-
- aLine.first.x = pWalk->currentPoint.x;
- aLine.first.y = pWalk->currentPoint.y;
- aLine.last.x = p->x;
- aLine.last.y = p->y;
-
- pWalk->currentPoint.x = p->x;
- pWalk->currentPoint.y = p->y;
-
- GXDrawLine(&aLine);
-
- return(false);
- }
-
-
-
- Boolean TestCurveTo(gxPoint p[3], TestWalkRec* pWalk);
- Boolean TestCurveTo(gxPoint p[3], TestWalkRec* pWalk)
- {
- gxCurve aCurve;
-
- aCurve.first.x = pWalk->currentPoint.x;
- aCurve.first.y = pWalk->currentPoint.y;
-
- aCurve.control.x = p[1].x;
- aCurve.control.y = p[1].y;
-
- aCurve.last.x = p[2].x;
- aCurve.last.y = p[2].y;
-
- pWalk->currentPoint.x = p[2].x;
- pWalk->currentPoint.y = p[2].y;
-
- GXDrawCurve(&aCurve);
-
- return(false);
- }
-
-
-
- Boolean TestClosePath( TestWalkRec* pWalk);
- Boolean TestClosePath( TestWalkRec* pWalk)
- {
- gxLine aLine;
-
- aLine.first.x = pWalk->firstPoint.x;
- aLine.first.y = pWalk->firstPoint.y;
- aLine.last.x = pWalk->currentPoint.x;
- aLine.last.y = pWalk->currentPoint.y;
-
- pWalk->currentPoint.x = pWalk->firstPoint.x;
- pWalk->currentPoint.y = pWalk->firstPoint.y;
-
- GXDrawLine(&aLine);
-
- return(false);
- }
-
-
- Fixed ClGetFixedShapeLength(gxShape theShape, Boolean useGXMath)
- {
- wide wLength;
- Fixed pathLength;
-
- if (useGXMath)
- GXGetShapeLength(theShape, 0, &wLength);
- else
- AccurateGetShapeLength(theShape, 0, &wLength);
-
- pathLength = (Fixed)wLength.lo;
-
- return(pathLength);
-
- }//ClGetFixedShapeLength
-
-
- main() {
-
- Boolean finishedEarly;
- gxPoint where = {ff(100), ff(300)};
- gxShape testPath;
- TestWalkRec walker;
- Fixed theLen, testLen, step;
- gxPoint location, tangent;
- gxLine aLine;
- gxColor aColor;
- long tix, oldTime, newTime;
-
- testPath = MakeThePath();
-
- aColor.space = gxRGBSpace;
- aColor.profile = nil;
- aColor.element.rgb.red = 0xFFFF;
- aColor.element.rgb.green = 0;
- aColor.element.rgb.blue = 0;
- GXSetShapeColor(testPath, &aColor);
- GXDrawShape(testPath);
-
- #define DRAWTHEM
- #define NUMBEROFSTEPS 25
-
- theLen = ClGetFixedShapeLength(testPath, false);
-
- #ifndef DRAWTHEM
- printf("Accurate length: %f\r\n", fix2float(theLen));
- #endif
-
- step = FixedDivide(theLen, ff(NUMBEROFSTEPS));
- tix = TickCount();
- for (testLen = ff(0); testLen <= theLen; testLen += step) {
-
- (void)AccurateShapeLengthToPoint(testPath, 0, testLen, &location, &tangent);
-
- #ifdef DRAWTHEM
- tangent.x = FixedMultiply(tangent.x, ff(5));
- tangent.y = FixedMultiply(tangent.y, ff(5));
-
- aLine.first.x = location.x;
- aLine.first.y = location.y;
- aLine.last.x = location.x - FixedMultiply(ff(5), tangent.y);
- aLine.last.y = location.y + FixedMultiply(ff(5), tangent.x);
-
- GXDrawLine(&aLine);
- #endif
-
- }//end for
- newTime = TickCount() - tix;
-
- /* Now do it the Built in Skia way */
- //GXMoveShape(testPath, ff(0), ff(300));
- //GXDrawShape(testPath);
-
- theLen = ClGetFixedShapeLength(testPath, true);
-
- #ifndef DRAWTHEM
- printf("GX Calculated length: %f\r\n", fix2float(theLen));
- #endif
-
- step = FixedDivide(theLen, ff(NUMBEROFSTEPS));
- {
- gxColor aColor;
- aColor.space = gxRGBSpace;
- aColor.profile = nil;
- aColor.element.rgb.red = 0x0000;
- aColor.element.rgb.green = 0xFFFF;
- aColor.element.rgb.blue = 0xFFFF;
- GXSetInkColor(GXGetShapeInk(GXGetDefaultShape(gxLineType)), &aColor );
- }
-
- tix = TickCount();
- for (testLen = ff(0); testLen <= theLen; testLen += step) {
-
- (void)GXShapeLengthToPoint(testPath, 0, testLen, &location, &tangent);
-
- #ifdef DRAWTHEM
- tangent.x = FixedMultiply(tangent.x, ff(5));
- tangent.y = FixedMultiply(tangent.y, ff(5));
-
- aLine.first.x = location.x;
- aLine.first.y = location.y;
- aLine.last.x = location.x + FixedMultiply(ff(5), tangent.y);
- aLine.last.y = location.y - FixedMultiply(ff(5), tangent.x);
-
- GXDrawLine(&aLine);
- #endif
-
- }//end for
-
-
- #ifndef DRAWTHEM
- oldTime = TickCount() - tix;
- printf("Time for old: %ld\r\n", oldTime);
- printf("Time for new: %ld\r\n", newTime);
- #endif
-
- GXDisposeShape(testPath);
-
- }
-